#pragma once

#include <list>
#include <map>

using namespace std;

//template<typename T>
struct CCycleDataNode{
    CCycleDataNode( const CString& root, const CString &data, list<CString> &link )
        :CycleRootKey(root),CycleDataPathByRoot(data),CycleLinkByRoot(link), IsCycleDuplicated(false){};
    CString CycleDataPathByRoot;   
	CString CycleDataPathByItem;   
    CString CycleRootKey;
	CString CycleItemKey;
	bool    IsCycleDuplicated;
    list<CString> CycleLinkByRoot;
    list<CString> CycleLinkByItem;
};
typedef multimap<CString, CCycleDataNode>				CycleMap;
typedef CycleMap::iterator								CycleMapInterator;
typedef pair<CycleMapInterator, CycleMapInterator>		CycleMapRange;//(course2.teacher, course2.cf);
typedef pair<CString, CCycleDataNode>					CycleMapPair;

//struct userdevice
//{
//	string m_devicename;
//	long m_deviced;
//	int m_devicePopedom;
//};
//
//typedef multimap<string, userdevice>	USERTABLE;        
//typedef USERTABLE::const_iterator		CIT;
//typedef pair<CIT, CIT>					Range;

//template<typename T>
class CCycleCompare
{
public:
    CCycleCompare(void);
    ~CCycleCompare(void);
    bool GenerateCycleLink( const std::multimap<CString, CString>& mapCycleData );
    CStringArray& GetUniqueCycleData( void );
    int GetUniqueCycleData( CStringArray& oCycleArray );

/// Attribute
private:


    list<CCycleDataNode> m_lstCycleData;
	//std::multimap<CString, CCycleDataNode> 
	CycleMap m_mapCycleData;

	//std::multimap<CString, CCycleDataNode>
	//void SetMapCycleData(std::multimap<CString, CCycleDataNode>& val) { m_mapCycleData = val; }
    CycleMap& GetMapCycleData() { return m_mapCycleData; }
    void SetMapCycleData( CycleMap& val ) { m_mapCycleData = val; }

    list<CCycleDataNode>& GetCycleDataList();
    void SetCycleDataList(list<CCycleDataNode>& val);

private: //Implement
    CString FormatCycleString( const CString& strCycleString, list<CString> &lstCycle );
    int  BuildSingleCycleLink( const CString& strCycleString, list<CString> &lstCycle );
    int RebuildCycleByItem( const CString& strItemKey );
    bool RebuildSingleCycleByItem( const CString& strItemKey, CCycleDataNode& oCycleNode );

	int CheckCycleDuplicate( CycleMap& oCycleMap );

};
